package com.bbx.taxi.client.Task;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Handler;

import com.bbx.androidapi.util.ToastUtil;
import com.bbx.api.sdk.model.official.passanger.Officail_ComboBuild;
import com.bbx.api.sdk.model.official.passanger.Official_StarBuild;
import com.bbx.api.sdk.model.official.passanger.Return.Officail_Combo;
import com.bbx.api.sdk.model.official.passanger.Return.Official_Star;
import com.bbx.api.sdk.net.base.JsonBuild;
import com.bbx.api.sdk.net.official.passanger.Officail_ComboNet;
import com.bbx.api.sdk.net.official.passanger.Official_StarNet;
import com.bbx.taxi.client.Bean.Value;
import com.bbx.taxi.client.Bean.Attribute.MainAttribute;
import com.bbx.taxi.client.Task.BaseAsyncTask;
import com.bbx.taxi.client.MyApplication;
import com.bbx.taxi.official.R;

/** 
 * @Path com.bbx.taxi.client.Task.MyStarTask.java
 * @Author 严旭文
 * @Date 2016-3-4 上午10:04:31
 * @Company 蓝海（福建）信息技术有限公司
 * @Description
 * 司机星星
 */
public class MyStarTask {
	private Activity context;
	public static MyStarTask instance;
	public StarTask mStarTask;
	public String order_id;
	public interface OnStarListener {
		/**
		 *获取司机星星
		 */
		public void onStarFinish(String order_id,int star);
	}

	static OnStarListener mOnStarListener = null;

	public static void setOnStarListener(OnStarListener l) {
		mOnStarListener = l;
	}
	public static MyStarTask getInstance(Activity context,String order_id,String driver_id) {
		instance = new MyStarTask(context,order_id,driver_id);
		return instance;
	}
	public MyStarTask(Activity context,String order_id,final String driver_id) {
		this.context = context;
		this.order_id=order_id;
		getStar(driver_id);
	
	}
	/**
	 * 获取司机星星
	 */
	public void getStar(String driver_id) {
		Official_StarBuild mOfficial_StarBuild=new Official_StarBuild(context);
		mOfficial_StarBuild.driver_id=driver_id;
		StarTask mStarTask=new StarTask(context, mOfficial_StarBuild);
		mStarTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
	}
	private class StarTask extends BaseAsyncTask {

		private Official_StarBuild mOfficial_StarBuild;

		public StarTask(Activity context, Official_StarBuild mOfficial_StarBuild) {
			super(context,false);
			this.mOfficial_StarBuild = mOfficial_StarBuild;
		}

		@Override
		public void onSuccess(Object object) {
			if (object != null) {
				Official_Star mOfficial_Star=(Official_Star)object;
				if(mOfficial_Star!=null){
					if (mOnStarListener != null) {
						mOnStarListener.onStarFinish(order_id,mOfficial_Star.getStar());
					}
				}else{
					ToastUtil.showToast(context, R.string.no_network);
					if (mOnStarListener != null) {
						mOnStarListener.onStarFinish(order_id,0);
					}
				}
				
			} else {
				ToastUtil.showToast(context, R.string.no_network);
				if (mOnStarListener != null) {
					mOnStarListener.onStarFinish(order_id,0);
				}
			}
		}

		@Override
		public void onFailed(int status, String msg) {
			ToastUtil.showToast(context, R.string.no_network);
			if (mOnStarListener != null) {
				mOnStarListener.onStarFinish(order_id,0);
			}
	
		}

		@Override
		protected Object doInBackground(Object... params) {
			// TODO Auto-generated method stub
			String json = new JsonBuild().setModel(mOfficial_StarBuild).getJson();
			return new Official_StarNet(context, json);
		}
	}

}
